<template>
    <Teleport to="body">
        <transition name="el-fade-in">
            <div class="ticket-share-dialog" v-if="visible">
                <div class="ticket-share-dialog__mask"></div>
                <div class="ticket-share-dialog__content">
                    <div class="ticket-share-dialog__title">分享链接</div>

                    <div class="share-link">
                        {{ shareLink }}
                        <el-icon @click="onCopy()" :size="18" color="#5085fb" style="cursor: pointer">
                            <CopyDocument />
                        </el-icon>
                    </div>

                    <div class="btn-group">
                        <div class="btn-close" @click="onClose()">关闭</div>
                    </div>
                </div>
            </div>
        </transition>
    </Teleport>
</template>
<script setup>
import { CopyDocument } from "@element-plus/icons-vue";
const visible = ref(false);
const shareCode = ref(undefined);

const shareLink = computed(() => {
    return location.origin + '?share_code=' + shareCode.value;
})

const onClose = () => {
    visible.value = false;
}

const onCopy = () => {
    copy(shareLink.value);
    Message().success("复制成功");
}

defineExpose({
    open(code) {
        visible.value = true;
        shareCode.value = code;
    }
})
</script>
<style lang="scss" scoped>
.ticket-share-dialog {
    position: fixed;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    z-index: 999;

    &__mask {
        position: relative;
        width: 100%;
        height: 100%;
        background-color: rgba($color: #000000, $alpha: 0.5);
    }

    &__title {
        font-size: 18px;
        margin-bottom: 20px;
    }

    &__content {
        position: absolute;
        top: 50%;
        left: 50%;
        width: 440px;
        background-color: #fff;
        transform: translate(-50%, -50%);
        border-radius: 10px;
        padding: 15px;

        .share-link {
            display: flex;
            align-items: center;
            justify-content: center;
            margin-top: 30px;

            .el-icon {
                margin-left: 10px;
            }
        }

        .btn-group {
            display: flex;
            align-items: center;
            justify-content: center;
            height: 40px;
            margin-top: 30px;


            .btn-close {
                width: 60px;
                height: 32px;

                display: flex;
                align-items: center;
                justify-content: center;
                border: 1px solid #ccc;
                border-radius: 4px;
                font-size: 14px;
                cursor: pointer;
            }
        }
    }

    &__title {
        text-align: center;
    }
}
</style>